package com.oauth.server.extend.config;

import com.oauth.server.extend.provider.SmsCodeAuthenticationProvider;
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * @作者: 林江
 * @创建时间: 2024/1/13
 * @功能: 自定义扩展oauth2配置
 */
public class CustomExtendConfigurer<B extends HttpSecurityBuilder<B>>
        extends AbstractHttpConfigurer<CustomExtendConfigurer<B>, B> {
    private UserDetailsService userDetailsService;

    public CustomExtendConfigurer(UserDetailsService userDetailsService) {
        this.userDetailsService = userDetailsService;
    }

    @Override
    public void configure(B builder) throws Exception {
        // 短信配置校验提供器
        SmsCodeAuthenticationProvider provider = new SmsCodeAuthenticationProvider();
        provider.setUserDetailsService(userDetailsService);
        builder.authenticationProvider(postProcess(provider));
    }
}
